package com.yvon.service.demo.jdk.function;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : Yvon
 * @since : 2021-09-26
 */
public class FunctionalInterfaceTest {

    private List<People> peopleList = new ArrayList<>();
    public void init(){
        peopleList.add(new People("LuoTianyan",23));
        peopleList.add(new People("ff",26));
        peopleList.add(new People("Tony",33));
    }


    public static void main(String[] args) {
        List<People> peopleList = new ArrayList<>();

        peopleList.add(new People("LuoTianyan",23));
        peopleList.add(new People("ff",26));
        peopleList.add(new People("Tony",33));

        // filter(peopleList);
        // predicate(peopleList);
        // consumer(peopleList);

        // supplier();
        function(peopleList);

    }


    public static void filter(List<People> peopleList) {
        List<People> filter = UserFilter.filter(peopleList, p -> ((People) p).getAge() > 25);
        System.out.println(filter);
    }

    public static void predicate(List<People> peopleList) {
        List<People> predicate = UserFilter.predicate(peopleList, p -> ((People) p).getAge() > 25);
        System.out.println(predicate);
    }

    public static void consumer(List<People> peopleList) {
        UserFilter.consumer(peopleList, p -> ((People) p).setAge(18));
        UserFilter.consumer(peopleList, System.out::println);
    }

    public static void supplier() {
        List<People> init = UserFilter.listFactory(5, () -> new People("init", 18));
        System.out.println(init);
    }

    public static void function(List<People> peopleList) {
        List<String> function = UserFilter.function(peopleList, (People p) -> "name:" + p.getName() + " ,age:" + p.getAge());
        System.out.println(function);
    }

}
